﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using Runda.CMS.Workflow;
using System.Text;

namespace Runda.CMS.Portal.Workspace
{
    public partial class NoticeMNG : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindNoticeList(1);
            }
        }
        private void BindNoticeList(int pageindex)
        {
            List<SqlDbParameter> parms = new List<SqlDbParameter>();
            int RecordCount = 0;
            SqlDbParameter parm = new SqlDbParameter();
            parm.ColumnName = "NoticeType";
            parm.ColumnType = DbType.Int32;
            parm.ParameterName = "@NoticeType";
            parm.ParameterValue = System.Convert.ToInt32(Enumerator.NoticeMessageType.Public);
            parm.QualificationType = SqlDbParameter.QualificationSymbol.Equal;
            parms.Add(parm);
            List<CtrtMyNoticeEntity> list = new CtrtMyNoticeBll().GetAll<CtrtMyNoticeEntity>(parms, "CreatedOn desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterNotice.DataSource = list;
            RepeaterNotice.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterNotice_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindNoticeList(1);
            }
        }
        protected void lnkbtnDelete_Click(object sender, EventArgs e)
        {
            if (noticeids.Value.Trim() != "")
            {
                string[] noticeidsArray = noticeids.Value.Trim().Split(new char[] { ';' });
                for (int index = 0; index < noticeidsArray.Length; index++)
                {
                    CtrtMyNoticeEntity entity = new CtrtMyNoticeBll().Get<CtrtMyNoticeEntity>(new Guid(noticeidsArray[index]));
                    new CtrtMyNoticeBll().LogicDelete(entity);
                    BindNoticeList(1);
                }
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindNoticeList(AspNetPager1.CurrentPageIndex);
        }

        protected void btnRefersh_Click(object sender, EventArgs e)
        {
            BindNoticeList(AspNetPager1.CurrentPageIndex);
        }

        protected void RepeaterNotice_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Label CreatedBy = e.Item.FindControl("CreatedBy") as Label;
                Label CreatedByName = e.Item.FindControl("CreatedByName") as Label;

                if (CreatedBy != null)
                {

                    if (CreatedBy.Text.Trim() != "")
                    {
                        CreatedByName.Text = new SystemBll().Get<SysUserEntity>(new Guid(CreatedBy.Text)).UserName;
                    }
                   
                }
            }
        } 
    }
}
